package com.service.bean.alarm;

import java.sql.Timestamp;
import java.text.MessageFormat;
import java.util.Date;

/**
 * 勾臂车箱体报警信息
 * @author lj
 *
 */
public class HookArmAlarm {
	/**
	 * 定位数据ID 
	 */
	public String signalId;
	/**
	 * 终端编号
	 */
	public String gpsNo;
	/**
	 * 箱体ID
	 */
	public String caseId;
	/**
	 * 箱体名称(不插入数据库, 仅提供给前端使用)
	 */
	public String caseName;
	/**
	 * 报警时间
	 */
	public Date alarmTime;
	/**
	 * 报警信息
	 */
	public String alarmInfo;
	/**
	 * 公司代码
	 */
	public String companyCode;
	/**
	 * 报警地点经度
	 */
	public double baiduLng;
	/**
	 * 报警地点纬度
	 */
	public double baiduLat;
	/**
	 * 报警状态
	 */
	public int status;
	/**
	 * 持续时间
	 */
	public long keepTime;
	/**
	 * <pre>
	 * 	连续的满溢报警的第一条报警时间</br>
	 * 如果是连续的满溢报警, 需要将该字段的值返回给前端</br>
	 * 如果本次报警是第一条报警, 可以返回该值, 也可以返回alarmTime</br>
	 * 该字段仅用作给前端展示, 不插入数据库
	 * </pre>
	 */
	public Date firstAlarmTime;
	
	public Object[] getAll() {
		Object[] arrs = new Object[11];
		arrs[0] = "'" + signalId + "'";
		arrs[1] = "'" + gpsNo + "'";
		arrs[2] = "'" + caseId + "'";
		arrs[3] = alarmTime == null ? alarmTime : "'" + new Timestamp(alarmTime.getTime()) + "'";
		arrs[4] = "'" + alarmInfo + "'";
		arrs[5] = "'" + companyCode + "'";
		arrs[6] = String.valueOf(baiduLng);
		arrs[7] = String.valueOf(baiduLat);
		arrs[8] = status;
		arrs[9] = keepTime;
		arrs[10] = "'" + caseName + "'";
		return arrs;
	}
	
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("\"GPSNO\":{0},");
		buffer.append("\"CaseId\":{1},");
		buffer.append("\"AlarmTime\":{2},");
		buffer.append("\"BaiduLng\":{3},");
		buffer.append("\"BaiduLat\":{4},");
		buffer.append("\"CaseName\":{5}");
		return MessageFormat.format(buffer.toString(), getAllForJson());
	}
	
	private Object[] getAllForJson() {
		Object[] arrs = new Object[6];
		arrs[0] = "\"" + gpsNo + "\"";
		arrs[1] = "\"" + caseId + "\"";
		// 连续的满溢报警时,给前端第一条满溢报警的时间; 否则就用当前报警的报警时间
		arrs[2] = firstAlarmTime != null ? ("\"" + new Timestamp(firstAlarmTime.getTime())) + "\"" : (alarmTime != null ? ("\"" + new Timestamp(alarmTime.getTime())+"\"") : ("\"" + new Timestamp(new Date().getTime())));
		arrs[3] = "\"" + String.valueOf(baiduLng) + "\"";
		arrs[4] = "\"" + String.valueOf(baiduLat) + "\"";
		arrs[5] = "\"" + caseName + "\"";
		return arrs;
	}
	
}
